package com.ruoyi.web.controller.activity;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.activity.domain.ActCommunity;
import com.ruoyi.activity.service.IActCommunityService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学校社团Controller
 * 
 * @author YZD
 * @date 2022-07-12
 */
@Controller
@RequestMapping("/activity/community")
public class ActCommunityController extends BaseController
{
    private String prefix = "activity/community";

    @Autowired
    private IActCommunityService actCommunityService;

    @RequiresPermissions("activity:community:view")
    @GetMapping()
    public String community()
    {
        return prefix + "/community";
    }

    /**
     * 查询学校社团列表
     */
    @RequiresPermissions("activity:community:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ActCommunity actCommunity)
    {
        startPage();
        List<ActCommunity> list = actCommunityService.selectActCommunityList(actCommunity);
        return getDataTable(list);
    }

    /**
     * 导出学校社团列表
     */
    @RequiresPermissions("activity:community:export")
    @Log(title = "学校社团", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ActCommunity actCommunity)
    {
        List<ActCommunity> list = actCommunityService.selectActCommunityList(actCommunity);
        ExcelUtil<ActCommunity> util = new ExcelUtil<ActCommunity>(ActCommunity.class);
        return util.exportExcel(list, "学校社团数据");
    }

    /**
     * 新增学校社团
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存学校社团
     */
    @RequiresPermissions("activity:community:add")
    @Log(title = "学校社团", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ActCommunity actCommunity)
    {
        return toAjax(actCommunityService.insertActCommunity(actCommunity));
    }

    /**
     * 修改学校社团
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ActCommunity actCommunity = actCommunityService.selectActCommunityById(id);
        mmap.put("actCommunity", actCommunity);
        return prefix + "/edit";
    }

    /**
     * 修改保存学校社团
     */
    @RequiresPermissions("activity:community:edit")
    @Log(title = "学校社团", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ActCommunity actCommunity)
    {
        return toAjax(actCommunityService.updateActCommunity(actCommunity));
    }

    /**
     * 删除学校社团
     */
    @RequiresPermissions("activity:community:remove")
    @Log(title = "学校社团", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(actCommunityService.deleteActCommunityByIds(ids));
    }
}
